unit SrvModule;

interface

uses
  SysUtils, Classes, DB, DBClient, ClientRowSet;

type
  TdmSrv = class(TDataModule)
    crsErrBill: TClientRowSet;
    crsErrProc: TClientRowSet;
    crsErrProcPROC_ID: TStringField;
    crsErrProcBILL_ID: TStringField;
    crsErrProcBILL_NO: TStringField;
    crsErrProcPROC_CODE: TIntegerField;
    crsErrProcPROC_CAP: TStringField;
    crsErrProcCAPTION: TStringField;
    crsErrProcCONTENT: TStringField;
    crsErrProcUSER_NO: TStringField;
    crsErrProcUSER_NAME: TStringField;
    crsErrProcCOMPANY: TStringField;
    crsErrProcCONTACTOR: TStringField;
    crsErrProcPHONENO: TStringField;
    crsErrProcPROC_TM: TStringField;
    crsErrProcGROUP_CODE: TStringField;
    crsErrProcNODE_NO: TStringField;
    crsErrProcNODE_NAME: TStringField;
    crsErrProcCALL_ID: TStringField;
    crsErrProcUPDATETIME: TStringField;
    crsErrProcSYS_ACCOUNT: TStringField;
    crsErrProcVERSION: TIntegerField;
    crsErrBillID: TStringField;
    crsErrBillBILL_NO: TStringField;
    crsErrBillCARGO_SOURCE: TStringField;
    crsErrBillIN_UNI_BILLNO: TStringField;
    crsErrBillIN_UNI_COMPNO: TStringField;
    crsErrBillIN_UNI_COMPNAME: TStringField;
    crsErrBillIN_UNI_PAYMODE: TStringField;
    crsErrBillOUT_UNI_BILLNO: TStringField;
    crsErrBillOUT_UNI_COMPNO: TStringField;
    crsErrBillOUT_UNI_COMPNAME: TStringField;
    crsErrBillOUT_UNI_PAYMODE: TStringField;
    crsErrBillTRUCK_NO: TStringField;
    crsErrBillOPDATE: TStringField;
    crsErrBillACC_CUSTNO: TStringField;
    crsErrBillSUB_BILL_NOS: TStringField;
    crsErrBillTSP_STATE: TIntegerField;
    crsErrBillTSP_STATE_CAP: TStringField;
    crsErrBillBATCHNO: TStringField;
    crsErrBillTSP_TYPE: TStringField;
    crsErrBillCARGO_NAME: TStringField;
    crsErrBillCARGO_VALUE: TFloatField;
    crsErrBillVOLUME: TFloatField;
    crsErrBillWEIGHT: TFloatField;
    crsErrBillFWEIGHT: TFloatField;
    crsErrBillCARGO_CNT: TIntegerField;
    crsErrBillOIL_COST: TFloatField;
    crsErrBillPARK_COST: TFloatField;
    crsErrBillOCD: TFloatField;
    crsErrBillOCD_STATE: TStringField;
    crsErrBillFEE: TFloatField;
    crsErrBillPRV_FEE: TFloatField;
    crsErrBillNXT_FEE: TFloatField;
    crsErrBillADD_DISP_FEE: TFloatField;
    crsErrBillADD_FETC_FEE: TFloatField;
    crsErrBillINSURANCE: TFloatField;
    crsErrBillPAY_MODE: TStringField;
    crsErrBillPAY_SIDE: TStringField;
    crsErrBillPAY_TYPE: TStringField;
    crsErrBillSRC_CUSTNO: TStringField;
    crsErrBillSRC_CUSTYPE: TStringField;
    crsErrBillSRC_COMP: TStringField;
    crsErrBillSRC_CONTACTOR: TStringField;
    crsErrBillSRC_CARDNO: TStringField;
    crsErrBillSRC_TEL: TStringField;
    crsErrBillSRC_CITY: TStringField;
    crsErrBillSRC_ADDRESS: TStringField;
    crsErrBillIS_OLDCUST: TIntegerField;
    crsErrBillDST_CUSTNO: TStringField;
    crsErrBillDST_CUSTYPE: TStringField;
    crsErrBillDST_CARDNO: TStringField;
    crsErrBillDST_COMP: TStringField;
    crsErrBillDST_CONTACTOR: TStringField;
    crsErrBillDST_TEL: TStringField;
    crsErrBillDST_CITY: TStringField;
    crsErrBillDST_ADDRESS: TStringField;
    crsErrBillFETCH_TM: TStringField;
    crsErrBillINPUT_TM: TStringField;
    crsErrBillSEND_TM: TStringField;
    crsErrBillDISP_TM: TStringField;
    crsErrBillARIV_TM: TStringField;
    crsErrBillRECV_TM: TStringField;
    crsErrBillGROUP_CODE: TStringField;
    crsErrBillGROUP_NAME: TStringField;
    crsErrBillSRC_NODE: TStringField;
    crsErrBillSRC_NODE_NAME: TStringField;
    crsErrBillDST_NODE: TStringField;
    crsErrBillDST_NODE_NAME: TStringField;
    crsErrBillCHG_NODE: TStringField;
    crsErrBillCHG_NODE_NAME: TStringField;
    crsErrBillCRT_NODE: TStringField;
    crsErrBillCRT_NODE_NAME: TStringField;
    crsErrBillFETCH_EMP_NO: TStringField;
    crsErrBillFETCH_EMP_NAME: TStringField;
    crsErrBillFETCH_EMP_TEL: TStringField;
    crsErrBillFETCH_COMP: TStringField;
    crsErrBillFETCH_COMP_NO: TStringField;
    crsErrBillDISP_EMP_NO: TStringField;
    crsErrBillDISP_EMP_NAME: TStringField;
    crsErrBillDISP_EMP_TEL: TStringField;
    crsErrBillDISP_COMP: TStringField;
    crsErrBillDISP_COMP_NO: TStringField;
    crsErrBillFET_UNI_INC: TFloatField;
    crsErrBillDSP_UNI_INC: TFloatField;
    crsErrBillSRC_EMP_INC: TFloatField;
    crsErrBillDST_EMP_INC: TFloatField;
    crsErrBillMON_BILLID: TStringField;
    crsErrBillCARGO_BILLID: TStringField;
    crsErrBillEXCEPT_CODE: TIntegerField;
    crsErrBillEXCEPT_CAP: TStringField;
    crsErrBillEXCEPT_INFO: TStringField;
    crsErrBillIS_ERROR: TIntegerField;
    crsErrBillCK_FEE: TSmallintField;
    crsErrBillCK_COD: TSmallintField;
    crsErrBillREMARK: TStringField;
    crsErrBillSMS_FLAG: TStringField;
    crsErrBillBROADCAST_FLAG: TStringField;
    crsErrBillSYS_ACCOUNT: TStringField;
    crsErrBillUPDATETIME: TStringField;
    crsErrBillVERSION: TIntegerField;
    crsErrBillACPT_PERSON: TStringField;
    crsErrBillSRC_FEE_STATE: TStringField;
    crsErrBillDST_FEE_STATE: TStringField;
    crsErrBillSUBMIT_FLAG: TIntegerField;
    crsErrBillTOTFEE: TFloatField;
    crsErrBillCLOSE_COD: TIntegerField;
    crsErrBillCLOSE_SRCFEE: TIntegerField;
    crsErrBillCLOSE_DSTFEE: TIntegerField;
    crsErrBillSRC_NODEINC: TFloatField;
    crsErrBillDST_NODEINC: TFloatField;
    crsErrBillDELIV_TYPE: TStringField;
    crsErrBillCK_DATES: TStringField;
    crsErrBillINPUTOR: TStringField;
    crsErrBillDELIV_CODE: TSmallintField;
    crsErrBillSTOCK_FEE: TFloatField;
    crsErrBillLICENSE_PLATE: TStringField;
    crsErrBillDRIVER: TStringField;
    procedure crsErrProcAfterInsert(DataSet: TDataSet);
    procedure crsErrBillAfterOpen(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure ShowErrorBill(condition:String);
    procedure ShowErrProc(billid:String);
  end;

function dmSrv: TdmSrv;

implementation

{$R *.dfm}

uses
  UniGUIVars, uniGUIMainModule, MainModule,expModule,uCommFunction;

function dmSrv: TdmSrv;
begin
  Result := TdmSrv(UniMainModule.GetModuleInstance(TdmSrv));
end;

{ TdmSrv }

procedure TdmSrv.crsErrBillAfterOpen(DataSet: TDataSet);
var
  billid:String;
begin
  if dataset.RecordCount > 0 then
  begin
    billid := dataset.FieldByName('id').AsString;
    self.ShowErrProc(billid);
  end;
end;

procedure TdmSrv.crsErrProcAfterInsert(DataSet: TDataSet);
var
  billid,billno:String;
begin
  billid := crsErrBill.FieldByName('id').AsString;
  billno := crsErrBill.FieldByName('bill_no').AsString;
  DataSet.FieldByName('proc_id').AsString := getguid;
  DataSet.FieldByName('bill_id').AsString := billid;
  DataSet.FieldByName('bill_no').AsString := billno;
  DataSet.FieldByName('SYS_ACCOUNT').AsString := dmexpress.UserInfo.SysAccount;
  DataSet.FieldByName('node_no').AsString := dmexpress.UserInfo.NodeNo;
  DataSet.FieldByName('NODE_NAME').AsString := dmexpress.UserInfo.NodeName;
  DataSet.FieldByName('USER_NO').AsString := dmexpress.UserInfo.UserNo;
  DataSet.FieldByName('USER_NAME').AsString := dmexpress.UserInfo.UserName;
  DataSet.FieldByName('PROC_TM').AsString := formatdatetime('yyyy-MM-dd HH:mm:ss',now);
end;

procedure TdmSrv.ShowErrorBill(condition: String);
var
  sqltxt:string;
  nodeno:string;
begin
  nodeno := dmexpress.UserInfo.NodeNo;
  sqltxt := 'select * from tsp_bill where is_error=1 and '+
            'group_code=' + quotedstr(dmexpress.UserInfo.GroupCode) + ' and ' +
            '(src_node=' + quotedstr(nodeno) + ' or ' +
            ' dst_node=' + quotedstr(nodeno) + ')';
  if condition <> '' then
    sqltxt := sqltxt + ' and ' + condition;

  dmexpress.OpenDataset(crsErrBill,sqltxt);


end;

procedure TdmSrv.ShowErrProc(billid: String);
var
  sqltxt:string;
begin
  sqltxt := 'select * from TSP_ERRBILL_PROC where bill_id=' + quotedstr(billid);
  dmexpress.OpenDataset(crsErrProc,sqltxt);
end;

initialization
  RegisterModuleClass(TdmSrv);

end.
